package day1_12.other;
// 双色球号码随机生成器,输入号码匹配中奖情况
import java.util.Random;
import java.util.Scanner;

public class DoubleColorBall {

    public static void main(String[] args) {
        int [] arr = createNumber();
        System.out.println("当前中奖号码为:");
        System.out.println("---------------------");
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
        System.out.println();
        System.out.println("---------------------");
        int[] userInputArr = userInputNumber();
//        for (int i = 0; i < userInputArr.length; i++) {
//            System.out.prin tln(userInputArr[i] + " ");
//        }
        int redCount = 0;
        int blueCount = 0;
        for (int i = 0; i < userInputArr.length-1; i++) {
            int redNumber = userInputArr[i];
            for (int j = 0; j < arr.length-1; j++) {
                if (redNumber == arr[j]) {
                    redCount++;
                    break;
                }
            }
        }
        int blueNumber = userInputArr[userInputArr.length-1];
        if (blueNumber == arr[arr.length-1]) {
            blueCount++;
        }
//        打印中奖情况
        if (redCount ==6 && blueCount == 1) {
            System.out.println("恭喜你,中奖一千万!");
        } else if (redCount == 6 && blueCount == 0) {
            System.out.println("恭喜你,中奖500万");
        } else if (redCount == 5 && blueCount == 1) {
            System.out.println("恭喜你,中奖3000");
        } else if ((redCount == 5 && blueCount == 0) || (redCount == 4 && blueCount == 1)) {
            System.out.println("恭喜你,中奖200");
        } else if ((redCount == 4 && blueCount == 0) || (redCount == 3 && blueCount == 1)) {
            System.out.println("恭喜你,中奖10");
        } else if ((redCount == 2 && blueCount == 1) || (redCount == 1 && blueCount == 1) || (redCount == 0 && blueCount == 1)) {
            System.out.println("恭喜你,中奖5");
        }else{
            System.out.println("谢谢参与");
        }
    }
    public static int[] userInputNumber(){
        int[] arr = new int[7];
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < arr.length; ) {
            System.out.println("请输入第" + (i + 1) + "个红球号码");
            int redNum = sc.nextInt();
//            判断数字范围
            if (redNum >= 1 && redNum <= 33) {
                boolean flag = contains(arr, redNum);
                if(!flag){
                    arr[i] = redNum;
                    i++;
                }else {
                    System.out.println("输入了重复的号码");
                }
            }else {
                System.out.println("当前红球号码超出范围");
            }
        }

        System.out.println("请输入蓝球号码:");
        while (true) {
            int blueNum = sc.nextInt();
            if (blueNum >= 1 && blueNum <= 16) {
                arr[arr.length-1] = blueNum;
                break;
            }else {
                System.out.println("当前蓝球号码超出范围");
            }
        }
        return arr;
    }
//    创建号码的方法
    public static int[] createNumber(){
        int [] arr = new int[7];

        Random random = new Random();
        for (int i = 0; i < 6; ) {
//            红色球号码范围1-33
            int redNum = random.nextInt(33) + 1;
            boolean flag = contains(arr,redNum);
            if(!flag){
                arr[i] = redNum;
                i++;
            }
        }
        int blueNum = random.nextInt(16) + 1;
        arr[arr.length-1] = blueNum;
        return arr;
    }
//    判断生成数字是否已经在数组中
    public static boolean contains(int[] arr, int number) {
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] == number) {
                return true;
            }
        }
        return false;
    }
}
